const path = require('path');
const fs = require('fs');
const mysqlConfig = require('../database/config.json');
const Op = require('sequelize').Op;
module.exports = (app) => {
  const exports = {};
  exports.security = {
    csrf: {
      enable: false,
      headerName: 'csrftoken',
    },
    domainWhiteList: ['*'],
  };
  exports.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
  };

  exports.siteFile = {
    '/favicon.ico': fs.readFileSync(path.join(app.baseDir, 'app/web/asset/images/favicon.ico')),
  };

  exports.view = {
    cache: false,
  };

  exports.vuessr = {
    layout: path.join(app.baseDir, 'app/web/view/layout.html'),
    renderOptions: {
      // 告诉 vue-server-renderer 去 app/view 查找异步 chunk 文件
      basedir: path.join(app.baseDir, 'app/view'),
    },
  };

  exports.logger = {
    consoleLevel: 'info',
    level: 'DEBUG',
    outputJSON: true,
    appLogName: `novel-web.log`,
    dir: path.join(app.baseDir, 'logs'),
  };

  exports.static = {
    prefix: '/public/',
    dir: path.join(app.baseDir, 'public'),
  };
  exports.keys = '123456';

  exports.middleware = ['locals', 'access'];
  exports.dingtalkRobot = {
    // 机器人的accessToken
    accessToken: '0d1d0bf11dec6f6d60d2e5918845d89956ef1d92ab22f2607159f3e25f168507',
  };
  exports.sequelize = {
    ...mysqlConfig.development,
    ...{
      operatorsAliases: {
        $eq: Op.eq,
        $ne: Op.ne,
        $gte: Op.gte,
        $gt: Op.gt,
        $lte: Op.lte,
        $lt: Op.lt,
        $not: Op.not,
        $in: Op.in,
        $notIn: Op.notIn,
        $is: Op.is,
        $like: Op.like,
        $notLike: Op.notLike,
        $iLike: Op.iLike,
        $notILike: Op.notILike,
        $regexp: Op.regexp,
        $notRegexp: Op.notRegexp,
        $iRegexp: Op.iRegexp,
        $notIRegexp: Op.notIRegexp,
        $between: Op.between,
        $notBetween: Op.notBetween,
        $overlap: Op.overlap,
        $contains: Op.contains,
        $contained: Op.contained,
        $adjacent: Op.adjacent,
        $strictLeft: Op.strictLeft,
        $strictRight: Op.strictRight,
        $noExtendRight: Op.noExtendRight,
        $noExtendLeft: Op.noExtendLeft,
        $and: Op.and,
        $or: Op.or,
        $any: Op.any,
        $all: Op.all,
        $values: Op.values,
        $col: Op.col,
      },
    },
  };
  return exports;
};
